<template>
	<view>
		<uv-navbar
			:leftIconColor="navstyle.txtColor"
			:titleStyle="titleStyle"
			:title="navstyle.title"
			:leftIcon="navstyle.leftIcon"
			:bgColor="navstyle.bgColor"
			:fixed="false"
			@leftClick="leftClick"
			:safeAreaInsetTop="false">
		</uv-navbar>
		<view class="password_box">
			<view class="password_list">
				<view class="password_laber">
					原登录密码
				</view>
				<input class="uni-input" password type="text" v-model="userForm.password" placeholder="请输入原密码" />
			</view>
			<view class="password_list">
				<view class="password_laber">
					新的密码
				</view>
				<input class="uni-input" password type="text" v-model="userForm.newpassword"  placeholder="请输入新的密码" />
			</view>
			<view class="password_list">
				<view class="password_laber">
					确认新密码
				</view>
				<input class="uni-input" password type="text" v-model="userForm.nwpassword" placeholder="请输入确认新密码" />
			</view>
			<button class="exitbtn" @click="savePassClick">确定</button>
		</view>
	</view>
	
</template>

<script>
	import {memberInfo,saveInfo} from '@/api/user.js';
	export default{
		onLoad() {
			memberInfo().then(response=>{
				this.userInfo = response.data;
				console.log(this.userInfo)
			});
			
		},
		data(){
			return{
				navstyle: {
					title: "修改登录密码",
					txtColor: "#333333",
					bgColor: "#FFFFFF",
					leftIcon: "arrow-left"
				},
				titleStyle: {
					fontWeight: 700
				},
				userInfo:{},
				userForm:{
					password:"",
					newpassword:"",
					nwpassword:"",
				}
			}
		},
		methods:{
			leftClick() {
				uni.reLaunch({
				  url: '/pages/user/login' // 替换成上一页的路径
				});
			},
			savePassClick(){
				if(!this.userForm.password){
					uni.showToast({
						title: '请输入原密码',
						duration: 2000
					});
					return
				}
				if(!this.userForm.newpassword){
					uni.showToast({
						title: '请输入新的密码',
						duration: 2000
					});
					return
				}
				if(!this.userForm.nwpassword){
					uni.showToast({
						title: '请输入确认新密码',
						duration: 2000
					});
					return
				}
				saveInfo({
					password:this.userForm.password,
					newpassword:this.userForm.newpassword,
					newpassword2:this.userForm.nwpassword,
				}).then(response=>{
					if(response.code==1){
						uni.reLaunch({
						  url: '/pages/user/login' // 替换成上一页的路径
						});
						uni.showToast({
							title: response.msg,
							duration: 2000
						});
					}
				})
				
				
			}
		}
	}
</script>

<style>
	.page{
		width: 100%;
		height: 100%;
	    background-color: #fafafa;
	}
	.password_box {
	    display: flex;
	    flex-direction: column;
	}
	.password_list {
	    display: flex;
	    flex-direction: row;
	    width: 100%;
	    padding: 5px 5px;
	    height: 50px;
	    border-bottom: 1px solid #d1d1d1;
	    align-items: center;
	}
	.password_laber{
	    width: 30%;
	    font-size: 13px;
	    text-align: center;
	}
	.password_list input {
	    height: 28px;
	    background-color: #fff;
	    padding: 5px 10px;
	    border-radius: 5px;
	    font-size: 13px;
	}
	.exitbtn{
	    width: 80%;
	    border-radius: 50px;
	    background: linear-gradient(135deg, #d66c6b, #ed6266);
	    font-size: 14px;
	    margin: 32px auto 0 auto;
	    color: #fff;
	    padding: 3px 0;
	    border: none;
	}
</style>